package com.malou.client.seguridad.usuario;

import java.util.List;

import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.CheckBoxListView;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class RolesPanel extends ContentPanel {
	
	private static UsuarioServiceAsync us = GWT.create(UsuarioService.class);
	public static ListLoader<ListLoadResult<Rol>> loaderListView;
	public static ListStore<BeanModel> storeListView;
	private CheckBoxListView<BeanModel> view;
	Integer user_id;
	public RolesPanel(){
		Usuarios.listRoles();
		user_id = 11;
		RpcProxy<List<Rol>> proxy = new RpcProxy<List<Rol>>() {  
		      @Override  
		      protected void load(Object loadConfig, AsyncCallback<List<Rol>> callback) {  
		    	  us.getRoles(user_id, callback);	  
		      }  
		    };
		    /*loaderListView = new BaseListLoader<ListLoadResult<Rol>>(proxy, new BeanModelReader()){  
		        @Override  
		        protected Object newLoadConfig() {  
		          ListLoadConfig config = new BaseListLoadConfig();  
		          return config;  
		        }  
		    
		      };*/
	     loaderListView = new BaseListLoader<ListLoadResult<Rol>>(proxy, new BeanModelReader());
	     storeListView = new ListStore<BeanModel>(loaderListView);
	     loaderListView.load();
	     
	     setCollapsible(true);  
	     setAnimCollapse(false);  
	     setFrame(true);  
	     setHeading("CheckBox ListView (0 items selected)");  
	     setWidth(300);  
	     setAutoHeight(true);  
	     setBodyBorder(false);
	     
	     view = new CheckBoxListView<BeanModel>();
		 
	     //view.setStore(Usuarios.storeListView);
	     view.setStore(storeListView);  
	     view.setDisplayProperty("usuario");
		 
	     view.getSelectionModel().addListener(Events.SelectionChange,  
	        new Listener<SelectionChangedEvent<BeanModel>>() {  
	  
	          public void handleEvent(SelectionChangedEvent<BeanModel> be) {  
	        	  
	          }  
	  
	        });
	     
	    /* view.addListener(Events.Attach, new Listener<ListViewEvent<BeanModel>>(){

			@Override
			public void handleEvent(ListViewEvent<BeanModel> be) {
				// TODO Auto-generated method stub
				loaderListView.load(user_id);
			}
	    	 
	     });
	     */
	     add(view);
	}
}
